const _ = require('lodash');

function isValidPdfSignature (signature) {
  const pdfHexFileSignature = '255044462d';
  const bufString = Buffer.from(signature.replace(/^data:application\/\w+;base64,/, ''), 'base64')
    .toString('hex');
  return bufString.startsWith(pdfHexFileSignature);
}

function getValueWithDefault(object, path, defaultValue) {
  const value = _.get(object, path);

  return value == null ? defaultValue : value;
}

module.exports.isValidPdfSignature = isValidPdfSignature;
module.exports.getValueWithDefault = getValueWithDefault;
